<?php

/**
 * Description of users
 *
 * @author Shermor
 */
class Visits extends Controller{

		function index(){
		
		$visitlist = $this->visits_info->retrieve_visit();
		
		$data = array();

		$data["visit"] =$visitlist;
		$session_user = $this->session->userdata('username');
								 $session_permission = $this->session->userdata('permission');
								$data['user'] = $session_user;
								$data['permission'] = $session_permission;
                   $data['title'] = "L & R Appointments";
               
                 $this->load->view('visit/index', $data);
                
		
		}
		function detail($wherestring){
		$visitlist = $this->visits_info->detail_visit($wherestring);

		$data = array();
		
		$data["visit"] = $visitlist['0'];
		$session_user = $this->session->userdata('username');
								 $session_permission = $this->session->userdata('permission');
								$data['user'] = $session_user;
								$data['permission'] = $session_permission;
		  $data['title'] = "L & R Appointments";
                
                 $this->load->view('visit/detail', $data);
                
		}
		function add($id){


		if (isset($_POST['vdate']) && isset($_POST['vtime']))
					{
							$this->form_validation->set_rules('vdate', 'Visit Date', 'required|trim');
							$this->form_validation->set_rules('vtime', 'Visit Time', 'required|trim');
							$this->form_validation->set_rules('purpose', 'Purpose', 'required');

							if ($this->form_validation->run() == FALSE)
							{
												$data['id'] = $id;
												$session_user = $this->session->userdata('username');
								 $session_permission = $this->session->userdata('permission');
								$data['user'] = $session_user;
								$data['permission'] = $session_permission;
												 $data['title'] = "L & R Appointments";
												 
                       $this->load->view('visit/addvisit', $data);
                    
							}
							else
							{

									$vdate = $_POST['vdate'];
									$vtime = $_POST['vtime'];
									$purpose = $_POST['purpose'];
									if (isset($_POST['action'])){
									$action = $_POST['action'];
									$docnotes = $_POST['docnotes'];
									}
									else{
									$action = "";
									$docnotes = "";
									}
									$other = $_POST['other'];

									$this->visits_info->insert_visit($id,$vdate,$vtime,$purpose,$action,$docnotes,$other);
									$session_user = $this->session->userdata('username');
								 $session_permission = $this->session->userdata('permission');
								$data['user'] = $session_user;
								$data['permission'] = $session_permission;
								$data['title'] = "L & R Appointments";
                 $this->load->view('header', $data);
                 $this->load->view('menu');
                   $this->load->view('visit/sucess');
                 $this->load->view('footer');
										
							}
					}
					else{
						$data['id'] = $id;
						 $session_user = $this->session->userdata('username');
								 $session_permission = $this->session->userdata('permission');
								$data['user'] = $session_user;
								$data['permission'] = $session_permission;
                                                  $data['title'] = "L & R Appointments";
                                                    
                                                     $this->load->view('visit/addvisit', $data);
                                                     
						
					}
		}
		function update($wherestring){

		if (isset($_POST['vdate']) && isset($_POST['vtime']))
					{
							$this->form_validation->set_rules('vdate', 'Visit Date', 'required|trim');
							$this->form_validation->set_rules('vtime', 'Visit Time', 'required|trim');
							$this->form_validation->set_rules('purpose', 'Purpose', 'required');

							if ($this->form_validation->run() == FALSE)
							{
								$visitlist = $this->visits_info->detail_visit($wherestring);

								$data = array();
								$data["visit"] = $visitlist['0'];
									$session_user = $this->session->userdata('username');
								 $session_permission = $this->session->userdata('permission');
								$data['user'] = $session_user;
								$data['permission'] = $session_permission;
								  $data['title'] = "L & R Appointments";
                                                                
                                                                 $this->load->view('visit/edit', $data);
                                                                 
								
							}
							else
							{
									$vdate = $_POST['vdate'];
									$vtime = $_POST['vtime'];
									$purpose = $_POST['purpose'];
                                                                        if (isset($_POST['action']) &&isset($_POST['docnotes']) ){
									$action = $_POST['action'];
									$docnotes = $_POST['docnotes'];
                                                                        }
                                                                        else{
                                                                           $action =" ";
									$docnotes = " ";
                                                                        }


									$other = $_POST['other'];
									$id =  $wherestring;

									$this->visits_info->update_visit($id,$vdate,$vtime,$purpose,$action,$docnotes,$other);

									
								  $data['title'] = "L & R Appointments";
									$session_user = $this->session->userdata('username');
								 $session_permission = $this->session->userdata('permission');
								$data['user'] = $session_user;
								$data['permission'] = $session_permission;
                                                                            
                                                                             $this->load->view('visit/sucess');
                                                                            
							}
					}
					else{
					$visitlist = $this->visits_info->detail_visit($wherestring);

					$data = array();
					$data["visit"] = $visitlist['0'];
					$session_user = $this->session->userdata('username');
								 $session_permission = $this->session->userdata('permission');
								$data['user'] = $session_user;
								$data['permission'] = $session_permission;
					  $data['title'] = "L & R Appointments";
                                            
                                             $this->load->view('visit/edit', $data);
                                             

					
					}

		}
		function delete($wherestring){
		$this->visits_info->delete_visit($wherestring);
$session_user = $this->session->userdata('username');
								 $session_permission = $this->session->userdata('permission');
								$data['user'] = $session_user;
								$data['permission'] = $session_permission;
                     $data['title'] = "L & R Appointments";
                
                 //-----------------------------change this
                 $this->load->view('visits/sucess');
                 
		

		}
}
//*EOF*//
